package com.lc.afbx.adapters;

import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiWoDeZiXun;
import com.lc.afbx.util.TimeUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/6/6.
 */
public class WoDeZiXunAdapter extends BaseAdapter {
    private List<GetApiWoDeZiXun.Data> dataList;
    private LayoutInflater inflater;
    private Context context;

    public WoDeZiXunAdapter(Context context, List<GetApiWoDeZiXun.Data> dataList) {

        inflater = LayoutInflater.from(context);
        this.dataList = dataList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_wodezixun, null);
            BaseApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);
            convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
            holder = new ViewHolder();

            holder.answer = (TextView) convertView.findViewById(R.id.answer_weiquan);
            holder.question = (TextView) convertView.findViewById(R.id.question_content_weiquan);
            holder.name = (TextView) convertView.findViewById(R.id.name_weiquan);
            holder.time = (TextView) convertView.findViewById(R.id.time_weiquan);
            holder.isReplay = (TextView) convertView.findViewById(R.id.isReplay);
            holder.touXiang = (SimpleDraweeView) convertView.findViewById(R.id.touxiang_weiquan);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name.setText(dataList.get(position).username);
        holder.time.setText(TimeUtil.times(dataList.get(position).posttime));
        holder.question.setText(dataList.get(position).title);

        holder.touXiang.setImageURI(Uri.parse(dataList.get(position).picurl));


//        Log.e("================", ("1".equals(dataList.get(position).restate)) + "     " + dataList.get(position).restate);

        if ("1".equals(dataList.get(position).restate)) {
            holder.isReplay.setText("回复：");
            holder.isReplay.setTextColor(context.getResources().getColor(R.color.textcolorHei));
            holder.answer.setText(dataList.get(position).reply);
        } else {
            holder.isReplay.setText("等待回复");
            holder.isReplay.setTextColor(context.getResources().getColor(R.color.titleColor));
            holder.answer.setText(null);
        }

        return convertView;

    }

    class ViewHolder {
        SimpleDraweeView touXiang;
        TextView name, time, question, answer, isReplay;
    }
//    R.layout.item_wodezixun,null
}
